class ShopController < ApplicationController

  before_action :authenticate_shoper!

  layout "shop"

  helper_method :current_shoper

  def authenticate_shoper!
    if current_shoper.blank?
      redirect_to shop_login_path, notice: "请先登录."
    else
      if current_shoper.shop.blank?
        session[:shoper_id] = nil
        redirect_to shop_login_path, notice: "不合法用户." 
      end
    end
  end

  private

  def current_shoper
    @current_shoper ||= Shoper.find_by_id(session[:shoper_id]) if session[:shoper_id]
  end

  def unauthorized
    redirect_to request.referrer || shop_home_path, alert: 'You are not authorized to perform this action.'
  end

end